package com.ljf.eslab.lab.controller;

import java.util.Arrays;
import java.util.Map;

import com.ljf.eslab.lab.annotation.NeedSid;
import com.ljf.eslab.lab.entity.TeacherEntity;
import com.ljf.eslab.lab.entity.UserEntity;
import com.ljf.eslab.lab.service.CourseService;
import com.ljf.eslab.lab.service.StuCourseService;
import com.ljf.eslab.lab.service.UserTokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ljf.eslab.lab.entity.StudentEntity;
import com.ljf.eslab.lab.service.StudentService;
import com.ljf.common.utils.PageUtils;
import com.ljf.common.utils.R;

import javax.servlet.http.HttpServletRequest;


/**
 * @author ljf
 * @email ljf@gmail.com
 * @date 2021-07-08 08:49:58
 */
@Slf4j
@RestController
@RequestMapping("lab/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @NeedSid
    @RequestMapping("/list")
    public R infoInHeader(@RequestHeader("token") String token, @RequestParam Map<String, Object> params , HttpServletRequest request){
        Integer sid = (Integer)request.getAttribute("sid");
        StudentEntity student = studentService.queryPageById(params,sid);
        log.debug("成功获取信息:{}",student.getRealName());
        return R.ok().put("student",student);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        StudentEntity student = studentService.getById(id);

        return R.ok().put("student", student);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StudentEntity student) {
        studentService.save(student);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StudentEntity student) {
        studentService.updateById(student);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        studentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
